<?
/**
 * Main.php
 *
 * This is an example of the main page of a website. Here
 * users will be able to login. However, like on most sites
 * the login form doesn't just have to be on the main page,
 * but re-appear on subsequent pages, depending on whether
 * the user has logged in or not.
 *
 */
include("include/session.php");
?>



<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="Description" content="Information about the Symposium on Racing & Gaming, presented by the University of Arizona Race Track Industry Program. Includes sponsors, exhibitors, panel sessions, award winners, photos, transcripts and presentations" />
    <meta name="Keywords" content="horseracing, horse racing, race track education, race horse, racehorse, greyhound tracks, horsetrack, thoroughbred racing, quarterhorse racing, horse breeding, pari-mutuel, parimutuel, equine education, greyhound racing, dog racing, harness racing, horse training, symposium on racing, multi-breed, racetrack industry, turf racing, rtip, gaming, betting, racetrack betting, University of Louisville, racetrack education, racetrack school, race track school, horseracing school, horseracing college, horse racing college, racetrack college, race track college, equine school, equine college, equine program, symposium on gaming" />
 
   <title>Symposium Login</title>
    <link href="css/rtip.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>

<div id="wrap">
    <div id="topbar">
	<a href="http://www.arizona.edu/" target="_blank"></a>
    </div>
    <div id="top">
        <div id="head_image"> </div>
    </div>

    <div id="page_head">
        <h2 id="left_head"> </h2>
        <h2 id="right_head"> </h2>

    </div>



<table>
<tr><td>
<h3>Scavenger hunt</h3>
<div class="whiteb">
<?
if(isset($_GET['clue'])){
	$clueNum = $_GET['clue'];
	$userName = $session->username;
	$previousClueNum = $database->previousScannedUser($userName);
	$interactionCount = $database->calcNumInteractions("scavenger".$clueNum);

	$clue = $database->scavangerClue($clueNum);
	$userPoints = $database->getUserPoints($userName);
	if($previousClue!=1) $wrongHint = $database->getWrongHint($previousClueNum);

	if($session->logged_in){
		echo "<h8> Welcome <b>$userName</b> </h8>";
		if($clueNum == 1){
			//if it is the first qr code from our booth.... till line 111
			//introduction
			if($database->userHasScanedUser($userName, "scavenger".$clueNum)){
				$previousClue = $database->scavangerClue($previousClueNum);
				echo "</br><font size='5'color='#990000'>$wrongHint</font></br>"
				."Here is your current clue:</br>"
				." <font size='5'color='#990000'>$previousClue</font></br>";
				if($interactionCount == 1){
					echo "<font size='5'color='#990000'>only 1 other person has scanned this code. </font>";}
					else{
						echo "$interactionCount other people have scanned this code";}
						echo
            	"</br>you have: <font size='5'color='#990000'>$userPoints</font> QRedits</br>";
			}
			//if the user has not scanned the first clue
			else {
				$database->userScanUser($userName, "scavenger".$clueNum);
				//adding the points when a user scanned the code that he has not scanned.
				$database->addUserPoints($userName,20);


				//needs to input the wording
				











				echo "</br>Your next clue is </br> <font size='5'color='#990000'>$clue</font></br>";
				$interactionCount = $database->calcNumInteractions("scavenger".$clueNum);
				if($interactionCount==1){
					echo "<font size='5'color='#990000'>Congratulations! You are the first one scanning this code!";
				}
				else if($interactionCount==2){
					echo "<font size='5'color='#990000'>1 other person has scanned this code </font>";}
					else{
						echo "<font size='5'color='#990000'>$interactionCount</font> people including you have scanned this code";}
						echo"  we have added 20 points for you to start with. "
						."You have </br> $userPoints QRedits";
			}
		}
		else{
			// user has already scanned the code
			//
			// if the user is scanning the wrong code:
			// then show the wrong hint
			// show the current hint
			// show the number of people has scanned the code.
			if($clueNum<>$previousClueNum+1){
				$userPoints = $database->getUserPoints($userName);

				$previousClueNum = $database->previousScannedUser($userName);
				$previousClue = $database->scavangerClue($previousClueNum);
				echo "</br><font size='5'color='#990000'>$wrongHint</font>"
				."<h6>Again, your current clue is: </h6>"
				."</br><font size='5'color='#990000'>$previousClue</font></br>";
				if($interactionCount==1){
					echo "<font size='5'color='#990000'>1</font> person has scanned this code. ";
				}
				else {
					echo "<font size='5'color='#990000'>$interactionCount</font> people have scanned this code";
				}
				echo"</br>You have </br> $userPoints QRedits</br>";
			}
			//if the user has not scanned the code yet
			// if is the 15 th, then congratualtes him/her
			else{
				if( $clueNum==16 ){
					// this is adding the points for the 15th clueNum.
					$database->addUserPoints($userName,100);
					$database->userScanUser($userName, "scavenger16");
					$interactionCount = $database->calcNumInteractions("scavenger".$clueNum);
					if($interactionCount==1){
						echo "</br>Congratulations! You are the<font size='5'color='#990000'> first </font>one to complete the Scavenger Hunt!</br>";
					}
					else if($interactionCount%10==2){
						echo "</br><font size='5'color='#990000'>Congratulations! You completed the Scavenger Hunt!</font></br>"
						."You are the <font size='5'color='#990000'>$interactionCount.nd </font>people who have completed this Scavenger Hunt.</br>";
							
					}
					else if($interactionCount%10==3)
					echo "</br><font size='5'color='#990000'>Congratulations! You completed the Scavenger Hunt!</font>"
					."</br>You are the <font size='5'color='#990000'>$interactionCount.rd </font>people who have completed this Scavenger Hunt.";
					else{
						echo "<font size='5'color='#990000'>Congratulations! You completed the Scavenger Hunt!</font>"
						."</br>You are the<font size='5'color='#990000'> $interactionCount.th </font>people who have completed this Scavenger Hunt.";
					}
					//reward points
					$userPoints = $database->getUserPoints($userName);
					echo "</br><font size='5'color='#990000'> we have added 100 points to your qredit account</font>"
					."</br><font size='5'color='#990000'>You now have </br> $userPoints QRedits</font></br>";
				}
				// all numbers other than 15th code
				else{
					// add points for discovering the nomral scavenger hunt QR code.
					$database->addUserPoints($userName,10);
					$userPoints = $database->getUserPoints($userName);
					$database->userScanUser($userName, "scavenger".$clueNum);
					$interactionCount = $database->calcNumInteractions("scavenger".$clueNum);
					echo"</br><h6>Your current clue is:</h6>"
					."</br><font size='5'color='#990000'> $clue </font></br>";
					if($interactionCount==1){
						echo "<font size='5'color='#990000'> You are the first one scanning this code!";
					}
					else if($interactionCount==2){
						echo "<font size='5'color='#990000'>1 other person has scanned this code </font>";}
						else{
							echo "<font size='5'color='#990000'>$interactionCount people including you have scanned this code</font>";
						}
						echo
                    "</br>We have awarded you 10 points for scanning this point"
                    ."</br>Now You have <font size='5'color='#990000'> $userPoints</font> QRedits</br>";
				}
			}
		}
	}
	else{
		?> You are not logged in -- redirecting to log-in page <script
	type="text/javascript"> top.window.location = 'main.php'; </script>

//add ?clue= #(#is clue number) into the QR code <?
	}


	//if(isset($_GET['clue'])){
	//    echo $_GET['clue'];
	//
	echo "[<a href=\"useredit.php\">Edit Account</a>]";
	if($session->isAdmin()){
		echo "</br>[<a href=\"admin/admin.php\">Admin Center</a>]";
	}
	echo "</br>[<a href=\"process.php\">Logout</a>]";

}
?></div>


</body>

